package com.ruoyi.project.cms.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.domain.ArticleTheme;
import com.ruoyi.project.cms.service.ArticleThemeService;

/**
 * 文章主题Controller
 * 
 * @author Su.Yuanlin
 * @date 2019-10-26
 */
@Controller
@RequestMapping("/site/ArticleTheme")
public class ArticleThemeController extends BaseController {
	private String prefix = "cms/article-theme";

	@Autowired
	private ArticleThemeService articleThemeService;

	@RequiresPermissions("cms:ArticleTheme:view")
	@GetMapping()
	public String ArticleTheme() {
		return prefix + "/ArticleTheme";
	}

	/**
	 * 查询文章主题列表
	 */
	@RequiresPermissions("cms:ArticleTheme:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ArticleTheme articleTheme) {
		startPage();
		List<ArticleTheme> list = articleThemeService.selectArticleThemeList(articleTheme);
		return getDataTable(list);
	}

	/**
	 * 导出文章主题列表
	 */
	@RequiresPermissions("cms:ArticleTheme:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(ArticleTheme articleTheme) {
		List<ArticleTheme> list = articleThemeService.selectArticleThemeList(articleTheme);
		ExcelUtil<ArticleTheme> util = new ExcelUtil<ArticleTheme>(ArticleTheme.class);
		return util.exportExcel(list, "ArticleTheme");
	}

	/**
	 * 新增文章主题
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存文章主题
	 */
	@RequiresPermissions("cms:ArticleTheme:add")
	@Log(title = "文章主题", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ArticleTheme articleTheme) {
		return toAjax(articleThemeService.insertArticleTheme(articleTheme));
	}

	/**
	 * 修改文章主题
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		ArticleTheme articleTheme = articleThemeService.selectArticleThemeById(id);
		mmap.put("articleTheme", articleTheme);
		return prefix + "/edit";
	}

	/**
	 * 修改保存文章主题
	 */
	@RequiresPermissions("cms:ArticleTheme:edit")
	@Log(title = "文章主题", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ArticleTheme articleTheme) {
		return toAjax(articleThemeService.updateArticleTheme(articleTheme));
	}

	/**
	 * 删除文章主题
	 */
	@RequiresPermissions("cms:ArticleTheme:remove")
	@Log(title = "文章主题", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(articleThemeService.deleteArticleThemeByIds(ids));
	}
}
